using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace LifeChess.Menu
{
    public class ScreenManager : MonoBehaviour
    {
        public List<Screen> screens;
        public int mainScreenIndex;

        [SerializeField]
        private Button backButton;
        private Stack<int> screenStack;

        public void OnBackButtonClick()
        {
            if (screenStack.Count == 0) return;

            var lastIdx = screenStack.Pop();
            screens[lastIdx].Hide();

            var newIdx = screenStack.Peek();
            screens[newIdx].Show();
        }

        public void StartScreen(int screenIndex)
        {
            if (screenStack.Count != 0)
            {
                var curIdx = screenStack.Peek();
                if (screenIndex == curIdx) return;

                screens[curIdx].Hide();
            }
            screenStack.Push(screenIndex);
            screens[screenIndex].Show();
        }
    }
}
